<div id="images_div<?php echo $id; ?>">
    <input style="display:inline-block" name="file" type="file" id="fileToUpload<?php echo $id; ?>"/>
    <div id="galleries<?php echo $id; ?>">
        <?php if (!empty($this->gallery) && is_array($this->gallery)) : ?>
            <?php foreach ($this->gallery as $k => $v) : ?>
                <span>
                    <img src="<?php echo WxUtil::getGoodsImgUrl($v,300,300); ?>" class="margin"/>
                    <input type="hidden" class="img_url" name='<?php echo $this->inputName ?>[<?php echo $k; ?>]'
                           value='<?php echo $v ?>'/>
                    <p>
                    <a class="del" href="#">删除</a> </p>
                </span>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</div>
<style type="text/css">
    #galleries {
        overflow: hidden;
    }

    #galleries img {
        width: 75%;
        height: 200px;
    }

    #galleries input {
        width: 82%;
    }

    #galleries span {
        width: 20%;
        float: left;
    }
</style>
<script type="text/javascript">
    $(function () {
        var index = 0;
        var index_val = 0;
        index = $("#galleries<?php echo $id; ?>>span").length;
        // if (index>0) {
        //     var last_calss=$("#galleries>span .img_url:last").attr('name');
        //     var name1=last_calss.split('[')[1];
        //     var name_index=name1.split(']')[0];
        //     index_val=parseInt(name_index)+1;
        // }else{
        index_val = index;
        // }
        // alert(index);
        //$('.img_item_length').val(index);
        $("#fileToUpload<?php echo $id; ?>").uploadify({
            buttonText: "请选择文件...",
            fileObjName: "file",
            fileTypeExts: "*.jpg;*.gif;*.png",
            swf: "/statics/plugins/uploadify/uploadify.swf",
            uploader: "/files/upload",
            multi: true,
            onUploadSuccess: function (file, dataStr, response) {
                //- 获取index
                //index_val=$("#galleries>span").length;
                var data = eval("(" + dataStr + ")");
                if (typeof(data.error) != "undefined") {
                    alert(data.error);
                } else {
                    if ($("#galleries<?php echo $id; ?> span img[attr-hash='" + data.hash + "']").length < 1) {
                        $("#galleries<?php echo $id; ?>").append("<span>" +
                            "<img src='/images/" + data.hash + ".png' class='margin' attr-hash='" + data.hash + "' cover='' />" +
                            "<input type='hidden' class='image-list' value='" + data.hash + "' name='<?php echo $this->inputName?>[" + index_val + "]' />" +

                            "<p><a class='del' href='#'>删除</a>" +
                            "</span>");
                        index_val++;
                    } else {
                        alert('相册图片不能重复添加');
                    }
                }
                index = $("#galleries<?php echo $id; ?>>span").length;
                $('.img_item_length').val(index);
            }
        });
        $("#galleries<?php echo $id; ?>").on("click", "span p a.del", function () {
            $(this).parent().parent().find('.img_url').val('');
            $(this).parent().parent().remove();
            var index = $("#galleries>span").length;
            if (index == 0) {

                $('.img_item_length').val('');
            } else {

                $('.img_item_length').val(index);
            }
            return false;
        });

        /*点击删除按钮，从新生成name序号*/
        $('.del').click(function () {
            $.each($('.img_url'), function (k, v) {
                $(k).attr('name', <?php echo $this->inputName?>+'[' + v + ']');
            })
        })
    });
</script>